package lx1;

public class Eater extends Thread{
    @Override
    public void run() {
        while(true){
            synchronized (Desk.lock){
                if(Desk.cnt == 0){
                    break;
                }
                else {
                    if(Desk.FoodFlag == 1){
                        System.out.println("已经吃完了一碗面条，还剩" + Desk.cnt + "碗！！！");
                        Desk.FoodFlag = 0;
                        Desk.lock.notifyAll();//唤醒跟这个锁绑定的所有线程

                    }
                    else{
                        try {
                            Desk.lock.wait();//让当前线程跟锁绑定
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
}
